﻿using System;
using UnityEngine;
using UnityEngine.EventSystems;

public class PEListener : MonoBehaviour,IPointerClickHandler,IPointerDownHandler, IPointerUpHandler,IDragHandler 
{
    public Action<PointerEventData, object[]> onClick;
    public Action<PointerEventData, object[]> onClickDown;
    public Action<PointerEventData, object[]> onClickUp;
    public Action<PointerEventData, object[]> onDrag;

    public object[] args = null;

    public void OnPointerClick(PointerEventData eventData) {
        onClick?.Invoke(eventData, args);
    }
    public void OnPointerDown(PointerEventData eventData) {
        onClickDown?.Invoke(eventData, args);
    }
    public void OnPointerUp(PointerEventData eventData) {
        onClickUp?.Invoke(eventData, args);
    }
    public void OnDrag(PointerEventData eventData) {
        onDrag?.Invoke(eventData, args);
    }
}

//使用说明：
/*protected void OnClick(GameObject go, Action<PointerEventData, object[]> clickCB, params object[] args) 
{
    PEListener listener = GetOrAddComponent<PEListener>(go);
    listener.onClick = clickCB;
    if(args != null) 
    {
        listener.args = args;
    }
}*/
